package lei.o_序列化;


import java.io.*;

public class SerializationExample {
    public static void serializeObject() {
        Person person = new Person("张三", 25, "zhangsan@example.com");

        try (
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person.txt"))) {

            // 序列化对象到文件
            oos.writeObject(person);
            System.out.println("对象已序列化并保存到文件: person.txt");
            System.out.println("序列化的对象: " + person);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
